package com.foreknow.demo6;

public class Rectangle {

    //求周长
    //通过控制台输出长、宽、周长、面积
    //定义两个属性 长length 宽witdh
    private int length;
    private int width;

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    //求面积
    public int getArea(){
        return (this.length*this.width);
    }
    //求周长
    public int getPer(){
        return (this.length+this.width)*2;
    }

    public void showAll(){
        System.out.println("长为" + this.length + "宽为" + this.width + "面积为" +getArea() + "周长为" + getPer());
    }

    public static void main(String[] args) {
        Rectangle rec = new Rectangle();
        rec.setLength(2);
        rec.setWidth(2);
        rec.showAll();
        System.out.println();
    }
}
